#!/bin/sh
# tlp - switch bluetooth/nfc/wifi/wwan on/off
#
# Copyright (c) 2024 Thomas Koch <linrunner at gmx.net> and others.
# SPDX-License-Identifier: GPL-2.0-or-later

# --- Source libraries

for lib in @TLP_TLIB@/tlp-func-base @TLP_FLIB@/25-tlp-func-rf @TLP_FLIB@/30-tlp-func-rf-sw; do
    # shellcheck disable=SC1090
    . "$lib"
done

# --- MAIN
carg1="$1"
if [ "$carg1" = "--version" ]; then
    print_version
    exit 0
fi

# read configuration: quit on error, trace allowed
read_config 1 0
parse_args4config "$@"
cprintf_init

add_sbin2path
self=${0##*/}

case $self in
    bluetooth|nfc|wifi|wwan)
        case $carg1 in
            on)
                device_switch "$self" on
                # shellcheck disable=SC2154
                echo_device_state "$self" "$_devs"
                ;;

            off)
                device_switch "$self" off
                echo_device_state "$self" "$_devs"
                ;;

            toggle)
                device_switch "$self" toggle
                echo_device_state "$self" "$_devs"
                ;;

            *)
                device_state "$self"
                echo_device_state "$self" "$_devs"
                ;;
        esac
        ;;

    *)
        cecho "Error: unknown device type \"$self\"." 1>&2
        do_exit 1
        ;;
esac

do_exit 0
